<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-刊例录入页</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript"
			src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
		<link type="text/css"
			href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css"
			rel="stylesheet" />
		<script type="text/javascript"
			src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<style type="text/css">
.add_div {
	padding: 0px 0;
	border: 1px solid #0078b6;
}

.add_div .table_add {
	width: 100%;
}

.add_div .table_add tr {
	height: 40px;
}

.add_div .table_add th {
	padding: 0px 0;
	text-align: right;
	color: #000000;
	font-size: 14px;
}

.add_div .table_add td {
	padding: 0px 0;
}
</style>
<script type="text/javascript">
	$(document).ready(function(){  
   //禁止退格键 作用于Firefox、Opera    
    document.onkeypress = banBackSpace;  
   //禁止退格键 作用于IE、Chrome   
	  document.onkeydown = banBackSpace;  
	});
	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外 
function banBackSpace(e){
	//alert(event.keyCode)
    var ev = e || window.event;//获取event对象   
    var obj = ev.target || ev.srcElement;//获取事件源 
    var t = obj.type || obj.getAttribute('type');//获取事件源类型     
    //获取作为判断条件的事件类型 
    var vReadOnly = obj.readOnly;
    var vDisabled = obj.disabled;
    //处理undefined值情况 
    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
    vDisabled = (vDisabled == undefined) ? true : vDisabled;
    //当敲Backspace键时，事件源类型为密码或单行、多行文本的，  
    //并且readOnly属性为true或disabled属性为true的，则退格键失效  
    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
    //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效    
    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
    //判断    
    if (flag2 || flag1) 
        event.returnValue = false;//这里如果写 return false 无法实现效果 
}
</script>

		<script type="text/javascript">
	$(function(){
		$('#dialog').dialog({
			autoOpen: false,
			width: 380,
			height: 410,
			show: "blind",
			hide:"slide",
			resizable: false,
			//position: [800,220]  //显示位置
			modal: true, overlay: { opacity: 0.5, background: "black" }	
		});
		$('#dialog_link').click(function(){
			$('#dialog').dialog('open');
			return false;
		})
		
		$('#dialog_01').dialog({
			autoOpen: false,
			width: 500,
			height: 510,
			show: "blind",
			hide:"slide",
			//position: [800,220]  //显示位置
			modal: true, overlay: { opacity: 0.5, background: "black" }	
		});
		$('#dialog_01_btn').click(function(){
			$('#dialog_01').dialog('open');
			return false;
		})
		$('#dialog_02_btn').click(function(){
			$('#dialog_01').dialog('open');
			return false;
		})
		
		$('#dialog_02').dialog({
			autoOpen: false,
			width: 380,
			height: 465,
			show: "blind",
			hide:"slide",
			resizable: false,
			//position: [800,220]  //显示位置
			modal: true, overlay: { opacity: 0.5, background: "black" },
			buttons: {
				"确认": function() {
					if($("#mediumSelectId").val()==null){
						alert("请选择一个媒体!");
						return false;
					}
					findMediaPriceByPriceID();
					$(this).dialog("close");
				},
				"取消": function() {
					$(this).dialog("close");
					$("#mediaNameID").val("");
				}
			}	
		});
		
		$('#mediaType').change(function(){
			if($("#mediaType").val()!=""){
				$('#dialog_02').dialog('open');
				$("#mediaName").val("");//情况媒体名称内容
				findAllMedia();
			}
			$("#mediaNameID").val("");//清空媒体名称
		})
		
		
		var msg ='${uploadErrorMessage}';
		var msg_01 = "${uploadErrorMessage_01}";
		var noError = '${noError}';
		var noError_01 = "${noError_01}";
		if(null !=msg && msg !=''){
			alert("媒体导入结束，请查看错误信息！");
			$("#mediaType").val("");
			$("#dialog_01_btn_spanId").show();
		}else if(null!=noError && noError!=''){
			$("#mediaType").val("");
			alert("媒体导入成功！");
		}
		
		if(null !=msg_01 && msg_01 !=''){
			alert("刊例导入结束，请查看错误信息！");
			$("#mediaType").val("");
			$("#dialog_02_btn_spanId").show();
		}else if(null!=noError_01 && noError_01!=''){
			$("#mediaType").val("");
			alert("刊例导入成功！");
		}
	});

	//清空合同名称
	function rewlset_hetong(){
		$("#contractName").val("");
	}
	
	//清空媒体名称
	function rewlset_media(){
		$("#mediaName").val("");
	}
	
	function findAllContract(){//查找根据合同名称查找所有合同
		$.getJSON("findAllMediasummByNameAction!findAllMediasummByName.action?"+ new Date(),{contractName:$("#contractName").val()},function(data){
			//清空显示层中的数据
			$("#xiangmuId").html("");
			$.each(data.contractList,function(i,value){
				$("#xiangmuId").append($("<option value='" + value.contractID + "'>" + value.contractName + "</option>"));
			});
		});
	}
	
	//合同列表双击
	function xiangmuDBlclick(){
		$("#dialog_link").val($("#xiangmuId").val());
		$("#dialog").dialog("close");
	}
	
	//媒体双击
	function mediumDBlclick(){
		findMediaPriceByPriceID();
		$("#dialog_02").dialog("close");
	}
	
	//根据媒体价格ID查找媒体名称
	function findMediaPriceByPriceID(){
		var priceID = document.getElementById("mediumSelectId").value;
			$.getJSON("findMediaPriceByPriceIDAction!findMediaPriceByPriceID.action?"+ new Date(),{priceID:priceID},function(data){
				if(data.mediaPrice != null){
					$("#mediaNameID").val(data.mediaPrice.mediasumm.mediaName);
				}
			});
	}
	
	//查找所有媒体l
	function findAllMedia(){
		var mediaType = document.getElementById("mediaType").value;
		$.getJSON("findMediumByMediumTypeAction!findMediumByMediumType.action?"+ new Date(),{mediaType:mediaType},function(data){
			//清空显示层中的数据
			$("#mediumSelectId").html("");
			$.each(data.mpList,function(i,value){
				$("#mediumSelectId").append($("<option value='" + value.priceID + "'>" + value.mediasumm.mediaName + "</option>"));
			});
		});
	}
	//根据媒体名称查找媒体
	function findAllMediaByName(){
		var mediaType = document.getElementById("mediaType").value;
		$.getJSON("findMediumByMediumTypeAction!findMediumByMediumType.action?"+ new Date(),{mediaName:$.trim($("#mediaName").val()),mediaType:mediaType},function(data){
			//清空显示层中的数据
			$("#mediumSelectId").html("");
			$.each(data.mpList,function(i,value){
				$("#mediumSelectId").append($("<option value='" + value.priceID + "'>" + value.mediasumm.mediaName + "</option>"));
			});
		});
	}
	
	
</script>
		<script type="text/javascript">
		//获取文件扩展名   
		function getFileExtendName(filePath){  
		   var extendName = '';  
		 if(filePath != null && $.trim(filePath).length > 0){  
		       filePath = $.trim(filePath);  
		       extendName = filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length);  
		    }  
		    return extendName;  
		}  
		  
		//验证文件扩展名   
		function checkFileExtendName(filePath){  
		    var extendName = getFileExtendName(filePath);  
		   //根据需求定制   
		   var accept_extend = new Array("xls","xlsx");  
		 	var flag = false;  
		 	if(extendName != ''){  
		      for(var i=0; i<accept_extend.length; i++){  
		          if(extendName.toLowerCase() == accept_extend[i])  
		              flag = true;  
		       }  
		   }  
		   return flag;  
		} 
		
	//媒体导入验证
	function checkFileType_hetong(){
		if($.trim($("#dialog_link").val())==""){
			alert("请选择合同编号！");
			document.getElementById("dialog_link").focus();
			return false;
		}
		if($.trim($("#uploadFile_01").val()) ==""){
			alert('请选择上传媒体附件！');
		    return false;
		}else  if(!checkFileExtendName($("#uploadFile_01").val())){
			alert('文件格式错误,请上传xlsx或xls格式的Excel文件！');
		     return false;
		}else{
			//$("#dialog_Upload_01").parent().appendTo("#form1");
			return true;
		}
	}
	//刊例导入验证
	function checkFileType_Medium(){
		$("#dialog_02").parent().appendTo("#form2");
		if($.trim($("#mediaType").val())==""){
			alert("请选择媒体类型！");
			document.getElementById("mediaType").focus();
			return false;
		}
		//if($.trim($("#mediumSelectId").val())==""){
		//	alert("请选择媒体类型下的媒体！");
		//	return false;
		//}
		
		if($.trim($("#mediaNameID").val())==""){
			alert("媒体名称不能为空！");
			return false;
		}
		
		if($.trim($("#uploadFile_02").val()) ==""){
			alert('请选择上传刊例附件！');
		    return false;
		}else  if(!checkFileExtendName($("#uploadFile_02").val())){
			alert('文件格式错误,请上传xlsx或xls格式的Excel文件！');
		     return false;
		}else{
			return true;
		}
	}
	//取消
	function doQuXiao(){
		if(confirm('您确认取消本次操作？')){
			window.location.href='mediaPriceAction.action?currentPage=1';
		}
	}
</script>

	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶部end -->

		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
					<div class="add_div">
						<table width="100%" cellpadding="0" cellspacing="0">
							<tr>
								<td>
									<div class="add_div"
										style="border-top-style: none; border-left-style: none; border-bottom-style: none;">
										<div class="add_div"
											style="border-top-style: none; border-left-style: none; border-right-style: none;">
											<table style="width: 100%;" cellpadding="0" cellspacing="0">
												<tr
													style="height: 30px; font-size: 16px; color: #000000; background: url(<%=path%>/images/banners30.jpg) repeat;">
													<td style="padding-left: 30px;">
														<b>媒体导入</b>
													</td>
												</tr>
											</table>
										</div>
										<form action="doUploadMeduaAction.action"
											onsubmit="return checkFileType_hetong();" id="form1"
											method="post" enctype="multipart/form-data">
											<table style="width: 100%;" cellpadding="0" cellspacing="0">
												<tr>
													<td>
														<table cellpadding="5" cellspacing="20" width="100%">
															<tr style="height: 45px;">
																<th width="35%"
																	style="font-size: 14px; text-align: right; color: #000000;">
																	<b>合同编号：</b>
																</th>
																<td width="65%">
																	<input type="text" name="contractID" class="text"
																		style="width: 225px;" id="dialog_link" />
																	<span style="color: red;">*</span>
																</td>
															</tr>
															<tr style="height: 40px;">
																<th width="35%"
																	style="font-size: 14px; text-align: right; color: #000000;">
																	导入媒体：
																</th>
																<td width="65%">
																	<input type="file" id="uploadFile_01"
																		name="uploadFile_01" style="width: 225px; border: solid 1px #999999; height: 22px;" />
																	<span style="color: red;">*</span>
																</td>
															</tr>
															<tr>
																<th width="35%"
																	style="font-size: 14px; text-align: right; color: #000000;">
																</th>
																<td width="65%">
																	<input type="submit" class="btn-title" value="导入媒体" />
																	<span id="dialog_01_btn_spanId" style="display: none;">&nbsp;&nbsp;
																		<input type="button" id="dialog_01_btn"
																			class="btn-title" value="导入媒体错误信息" /></span>
																	&nbsp;&nbsp;
																<input type="button" class="btn-title" value="取消" onclick="doQuXiao();" />
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>

											<div id="dialog" title="合同名称列表" style="display: block;">
												<table width="0" border="0" cellspacing="0" cellpadding="0">
													<tr>
														<td>
															<input type="text" style="width: 250px" id="contractName"
																class="text" />
															&nbsp;
															<input type="button" class="btn-title" value="搜索"
																onclick="findAllContract();" />
															&nbsp;
															<input type="button" class="btn-title" value="重置"
																onclick="rewlset_hetong();" />
														</td>
													</tr>
													<tr>
														<td style="padding-top: 5px;">
															<select id="xiangmuId" multiple="multiple"
																style="width: 100%; height: 335px; overflow: hidden"
																ondblclick="xiangmuDBlclick();">
																<s:iterator id="c" value="contractList">
																	<option title="${c.contractName}"
																		value="${c.contractID}">
																		${c.contractName}
																	</option>
																</s:iterator>
															</select>
														</td>
													</tr>
												</table>
											</div>
										</form>
									</div>
								</td>
								<td>
									<div class="add_div"
										style="border-left-style: none; border-top-style: none; border-right-style: none;">
										<table style="width: 100%;" cellpadding="0" cellspacing="0">
											<tr
												style="height: 30px; font-size: 16px; color: #000000; background: url(<%=path%>/images/banners30.jpg) repeat;">
												<td style="padding-left: 30px;">
													<b>刊例导入</b>
												</td>
											</tr>
										</table>
									</div>
									<form action="doUploadMediumAction.action" id="form2"
										onsubmit="return checkFileType_Medium();" method="post"
										enctype="multipart/form-data">
										<table style="width: 100%;" cellpadding="0" cellspacing="0">
											<tr>
												<td valign="top">
													<table cellpadding="5" cellspacing="20" width="100%">
														<tr>
															<th width="35%"
																style="font-size: 14px; text-align: right; color: #000000;">
																<b>媒体类型：</b>
															</th>
															<td width="65%">
																<s:select id="mediaType" name="mediaType"
																	list="mediaTypeList" listKey="id" listValue="datavalue"
																	cssStyle="width:225px;" headerKey=""
																	headerValue="--请选择--">
																</s:select>
																<span style="color: red;">*</span>
															</td>
														</tr>
														<tr>
															<th width="35%"
																style="font-size: 14px; text-align: right; color: #000000;">
																<b>媒体名称：</b>
															</th>
															<td width="65%">
																<input type="text" class="text" id="mediaNameID" readonly="readonly" style="width:223px;"/>
																<span style="color: red;">*</span>
															</td>
														</tr>
														<tr>
															<th width="35%"
																style="font-size: 14px; text-align: right; color: #000000;">
																导入刊例：
															</th>
															<td width="65%">
																<input type="file" id="uploadFile_02"
																	name="uploadFile_02" style="width: 225px; border: solid 1px #999999; height: 22px;" />
																<span style="color: red;">*</span>
															</td>
														</tr>
														<tr>
															<th width="35%"
																style="font-size: 14px; text-align: right; color: #000000;">
															</th>
															<td width="65%">
																<input type="submit" class="btn-title" value="导入刊例" />
																<span id="dialog_02_btn_spanId" style="display: none;">&nbsp;&nbsp;
																		<input type="button" id="dialog_02_btn"
																			class="btn-title" value="导入刊例错误信息" /> </span>
																&nbsp;&nbsp;
																<input type="button" class="btn-title" value="取消" onclick="doQuXiao();" />
															</td>
														</tr>
													</table>
												</td>
											</tr>
										</table>

										<div id="dialog_02" title="媒体列表" style="display: block;">
											<table width="0" border="0" cellspacing="0" cellpadding="0">
												<tr>
													<td>
														<input type="text" style="width: 250px" id="mediaName"
															class="text" />
														&nbsp;
														<input type="button" class="btn-title" value="搜索"
															onclick="findAllMediaByName();" />
														&nbsp;
														<input type="button" class="btn-title" value="重置"
															onclick="rewlset_media();" />
													</td>
												</tr>
												<tr>
													<td style="padding-top: 5px;">
														<select id="mediumSelectId" name="priceID"
															multiple="multiple"
															style="width: 100%; height: 335px; overflow: hidden"
															ondblclick="mediumDBlclick();">
														</select>
													</td>
												</tr>
											</table>
										</div>
									</form>
								</td>
							</tr>
						</table>


						<div id="dialog_01" title="导入后的错误信息" style="display: none;">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td style="color: red;">
											${uploadErrorMessage}
											${uploadErrorMessage_01}
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<!-- 底部end -->
	</body>
</html>
